package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT ID,`PASSWORD` FROM t_user WHERE USERNAME= #{username}")
    UserVO findUserByUsername(@Param("username") String username);

    @Select("SELECT tr.ID,tr.KEYWORD FROM t_role tr, t_user_role tur WHERE tr.ID=tur.ROLE_ID AND tur.USER_ID=#{uid} ")
    List<RoleVO> findRoleInfoByUserId(@Param("uid") Integer uid);

    @Select(" SELECT tp.KEYWORD FROM t_role_permission trp, t_permission tp WHERE trp.PERMISSION_ID=tp.ID AND trp.ROLE_ID=#{rid}")
    List<Permission> findPermissionInfoByRoleId(@Param("rid") Integer rid);
}
